TARGET = xTos

CFLAGS	+= -DSYSDEF_PARSER_ON_HOST -DXML_SHM_DIRECT_WRITE
CFLAGS 	+= -DOBJID_HEADER=\"./target/cmsXml_obj_id.h\"
CFLAGS	+= -DOBJIDTABLE_HEADER=\"./target/cmsXml_oid_table.h\"
CFLAGS	+= -DOBJ_HEADER=\"./target/cmsXml_object.h\"
CFLAGS	+= -DINXCNT_HEADER=\"./target/cmsXml_index_count.h\"
CFLAGS	+= -DSTATUSFUNC_HEADER=\"./target/cmsTask_statsFunc.h\"
CFLAGS	+= -DSTATUSFUNC_TABLE=\"./target/cmsTask_statsTable.c\"

CFLAGS	+= -DSYS_DEF_XML_FILE=\"sysdef.xml\"
CFLAGS	+= -DPRE_DEF_XML_FILE=\"predef.xml\"
CFLAGS	+= -DPRE_CONFIG_PATH=\"preConf/\"

CFLAGS	+= -DCUS_DEF_XML=\"$(CMS_BASE_DIR)/$(DEF_CONF_FILE_XML)\"
CFLAGS	+= -DCUS_DEF_ENC=\"$(CMS_LIB_DIR)/$(DEF_CONF_FILE_ENC)\"
CFLAGS 	+= -DPRE_DEF_SHM=\"$(CMS_LIB_DIR)/$(PRE_CONF_FILE_SHM)\"


LD_LIBRARY_PATH = $(XML_LIB_DIR)
export LD_LIBRARY_PATH

LDFLAGS += -lxmlToShm -lexpat

#Support for CMS Phase 1
CFLAGS += -DCMS_XML_PARSE_PHASE_1

CFLAGS += -I$(CMS_LIBMDM_DIR)




SOURCES = $(wildcard *.c)
HEADERS = $(wildcard *.h)
OBJECTS = $(patsubst %.c, %.o, $(SOURCES))


.PHONY: prepare all
all: prepare $(TARGET)
	@echo "--------check xml file and generate header files-------------------------"
	./$(TARGET)
	@echo "--------check xml end----------------------------------------------------"
	@if [ -f $(CMS_TASK_DIR)/cmsTask_statsTable.c ] ; then \
		cmp -s target/cmsTask_statsTable.c $(CMS_TASK_DIR)/cmsTask_statsTable.c;\
		if [ $$? -ne 0 ]; then\
			cp target/cmsTask_statsTable.c $(CMS_TASK_DIR)/;\
		fi;\
	else\
		cp target/cmsTask_statsTable.c $(CMS_TASK_DIR)/;\
	fi;
	cp target/*.h $(CMS_INC_DIR)
	cp $(HEADERS) $(CMS_INC_DIR)
	@echo "###################################"
	@echo "#        $(TARGET)"
	@echo "#        Build up successfully"
	@echo "###################################"	

prepare:
	@if [ ! -d target ]; then\
		mkdir target;\
	fi;

$(TARGET): $(OBJECTS)
	@echo OBJECTS=$(OBJECTS)
	$(CC) -g $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)

$(OBJECTS):%.o:%.c
	@#printf "  CC      $(*).c\n"
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	@echo "###################################"
	@echo "#        clean $(TARGET) "
	@echo "###################################"		
	rm -rf $(OBJECTS)
	rm -rf $(TARGET)
	rm -rf *.o *.d *.so
	rm -rf target
	rm -rf pdm.c
	rm -rf $(CMS_TASK_DIR)/cmsTask_statsTable.c
